<?php error_reporting (E_ALL ^ E_NOTICE);
include('/includes/config.php');
function connectlogin() {
$account = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db(''.MYSQL_BASE_LS.'', $account); 
}
function connectgame() {
$game = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db(''.MYSQL_BASE_GS.'', $game);
}
function connectshop() {
$shop = mysql_connect(''.MYSQL_HOST.'', ''.MYSQL_USER.'', ''.MYSQL_PASS.'') or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db(''.MYSQL_BASE_SHOP.'', $shop);
}
//Account Managment Area
function cryptPassword($password)
{
	if($password != "")
		return mysql_escape_string(base64_encode(pack("H*", sha1(utf8_encode($password)))));
}
function isEmail($email) {
	return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
function coins($name){
	connectlogin();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `account_data` WHERE `name`='$name'");
	$result = mysql_fetch_array($query);
	echo $result['shop_points'];

}
function sitename($shopid) {
connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `settings` where `id` = '$shopid'");
	$result = mysql_fetch_array($query);
	return $result['sitename'];
}
function getterms() {
echo'<a href="login.php">Blah!</a>';
}
function getskin($shopid) {
connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `settings` where `id` = '$shopid'");
	$result = mysql_fetch_array($query);
	return $result['theme'];
}
function displayToMk($date){ 
  $date = explode(" ", $date); 
  $date[0] = explode("-", $date[0]); 
  $date[1] = explode(":", $date[1]); 
  return mktime($date[1][0], $date[1][1], $date[1][2], $date[0][1], $date[0][2], $date[0][0]); 
}
function getsnews() {
connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `news` ORDER BY id DESC");
	while ($result = mysql_fetch_array($query))
	{
		$counter++;
$alt = ( $counter % 2 == 0 ) ? ('1') : ('2');
$sqltimestamp = $result['date'];
	echo '<li>
	<div id="news'.$alt.'">
	<div id="newstitle">
	'.$result['title'].'<div id="newsdate">'.date("M j", displayToMk($sqltimestamp)).'</div>
	</div>
	
	<div id="newsbody">'.$result['body'].'</div>
	</div>
	</li>';
	}
}
function shop_list_item($type,$stype){
	connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `items` WHERE `active`='1' and `type`='$type'");
	$counter = 0;
	echo '<table width="100%"><tr>';
	while($result = mysql_fetch_assoc($query))
	{
if ($counter % 3 == 0)
{
	echo '</tr><tr>';
}
echo '<td align="left" style="padding:15px">
<div id="items">
	<div id="item">
		<form method="POST" action="buy.php">
		<input type="hidden" name="item" value="'.$result['id'].'">
		<a class="yg-iconlarge yg-notext" href="http://aion.yg.com/item/'.$result['name'].'?id='.$result['code'].'">
		&nbsp;
		</a>
	<br />
	'.$result['name'].'
	<br />
	<b>Quantity '.$result['amount'].'</b>
	<br />
	<b>Price '.$result['price'].'GP</b>
	<br />
	<input type="submit" class="btn_list_select" name="Buy" value="Buy"></form>
	</div>
</div></td>';
$counter++;	
}
echo '</tr></table>';
}
function shop_list_cat(){
	connectshop();
	//mysql_query("SET NAMES $database_encoding");
	$query = mysql_query("SELECT * FROM `catagories` WHERE `active`='1'");
	$counter = 0;
	while($result = mysql_fetch_assoc($query))
	{
		echo'<li><a href="#tabs-'.$result['type'].'">'.$result['name'].'</a></li>';
	}
}
?>